Made a few changes so it will run in a distributed setup.