reduced repetition in wordInGrid method