refactored basic genetic algorithm code