ruby refactor, using function.recognizeWords