Switched to 'for' in main loop, new (broken) optimization routine.