refactored phpcode