use length() instead of keeping count