More refactoring and simplification