modifications that I had in the other repo, save memory and some new php standards