model refactor, error handling for login