working version with logout