Added Logout and some error checking