working version where all computations are done only to the non-empty cubes (both in local & global steps)