Fix for PHP 5.2 compatibility (changed is_a to instanceof)