Cleanup and add failsafe mode