Some fixes for compatibility with PHP 5.3 which was neglected in the original PR