Refactoring corrected, safety analysis working