Tidied and re-factored cluster.js