User logout refactoring