changes to code structure and fixed greedy2.