SI-7614 Reduce temporal object creation.

Instead of using Tuple/Option/foldLeft, use imperative style to
reduce the temporal object creation.