More refactoring to simplify code