Added code to logout the user and few more checks.