refactor for PHP 5.3 and to be a bit better in general