Pull a count() out of a for() loop

To speed it up. Per #138.