adding logging in logout
code refactor and identation reformatting