bugfixes, plus compat with php 5.3