Refactor for authentication