first final version of greedy, maybe with a lot of crap