More refactoring/fixing