some bug fixes in login/logout function