Improve the logic of login