Refactoring and safety checks