Bugfix and refactor.

Bugfix: Loop over the dimensions was iterating (dimension^2) times, which
is dimension XOR 2, not dimension*dimension. Switched to dimension**2.

Refactor: Split main loop into outer and inner. The outer varies user_steps
times, the inner varies dimension^2 times.