More refactoring and clean-up