Refactoring, moving global vars to objects. Removing redundant code.