added comments in the php to better explain what is going on