refactored the method 'login' and removed some useless code