Modified so that outer loop is Y (height), then X and Z