Refactored login and register