optimized version of lettercount.py