Avoid using count() if not really needed

Count is an expensive operation. See http://maettig.com/code/php/php-performance-benchmarks.php.