Don't calculate category length on every loop iteration