Fixed logout and added some tests.