Refactoring Login and fix tests