Refactor login helper