Edited calc_stack_dist(). Not important commit. Might be erased.