Various refactoring before a major paradigm change

* Created constants
* Renamed funny variables
* Changed closest match algorithm (this will be changing again)