Refactored code, including breaking up genetic algorithm into sub-functions.