More refactoring and cleaning