did some refactoring and added a logout() function ready to be hooked up to a logout button