optimizing read counting script (from pair programming)