Updated for better PHP compatibility