Fixed logout and add scheduler for cleanup.