Refactored login controller