Added some more comments to 3D algorithm, and fixed a bug that affected some of the degenerate cases.