Use extract method to simplify compile_hash

This refactoring addresses two concerns identified through code climate:
compile_hash is very complex and has duplication.

DRYing up setting population to address duplication.

Using extract method on other bits of logic to clean up this method.