Improve the login and add test cases