Move safe_apply to apply.c