refactored safe php mode