Reimplemented logout and fixed issue 1332