Fixed a PHP 5.3 specific issue
Moved some code around