Updated for php5 support