More refactoring

Cleaning and moving around code.