More refactoring of controller code