HMM refactoring to combine 2D and 3D. 2D might be slower.