Fixes from itvm integration

Mostly itvm related changes. Mostly stuff to make the code more pythonic (iterate over the lists themselves instead of indexes for instance).
In the previous version we ended up trying the same jobs again and again in an (close to?) infinite loop, this stuff makes it try each task just once per iteration.