logout logic and fix to unit tests