Fixed and simplified word checking algorithm.