Better logging, and logout function