completed isValidWord function