replaced .length with .count() calls