ENH: Refactor and improvements to FourDD algorith