Added login and small refactoring