updated php code from victor's branch