genetic algorithm partially working
centralized some repeated code