Made the code more PHP 5.2 compatible