refactor logout code, mdb logout working