refactor C# portion, update variable name in Java (words -> terms)