Refactored logout a bit. Still needs more.