Added word detection code