Fixed shutdown procedure

The master node now waits for all slave nodes to confirm that they have shut down before shutting itself down...