More refactoring to clean up code