Implement distributed planning as a regular optimizer

... and a few other changes