Replaced more than 100 lines with 10.

Calc3d is now much faster and can handle more than 1000 layers if
needed.