This is an optimization playground. The code is very ugly and terribly slow. Try to use some of the concepts learned on the presentation to make it optimal.