Converted to PHP for easier updating