implemented the word_is_valid function