Implemented logout and generally fixed the in/out sequence. #69