refactor and add logoug
refactoring cleanup, added logout