Reorganizes login and controller code