Make it more efficient by avoiding recomputing in the inner loop.

Signed-off-by: David Brainard <brainard@psych.upenn.edu>