User logout and some refactorings