Refactored safe_compare workaround.