Cluster support

This is #119 rebased on top of the latest master with style cleanup.