Improve login logic. Add util package.