Logout logic implemented and tested, minor refactorings, minor changes in login
Real logout logic implemented, there was mistake in previous commit.