updated greedy, but still a bug