More refactoring and separating code