Refactor login