Implemented proper logout and some bug fixes