clean up and make it compatible with PHP 5.3