Added logout functionality and slight refactoring to remove some unessecary code