a working version - no genetic algorithm