Increased performance by approx 2x by reducing loops.