Initial work on code cleanup and refactoring
More refactoring, done for now