got HLL to work in 3D by moving the for-loop body outside the function