refactor login js a bit