Moved code from main controller to login controller, where it should be!!