rewritten for more efficient word and letter processing