refactored login system