Safemode code revision and documentation