Refactoring, editing old crappy code
Yet more refactoring and optimizing
Optimization #1
Optimization #2 and #3
Last change, final revision