expanded the greedy method to both 3D and 2D

Used templates so I could define some of the reusable classes once