Added last Java changes and now porting it all to PHP