Fix logout + some code cleanup