Rewrites to support migration to PHP 5.4