Made new greedy and did some refactoring.