More refactoring and re-ordering