fixed bugs on PHP 5.2