Fixed 500 when trying to log out and added test