Simplify code a bit, and fix a bug that was breaking perlbmk