lots of small fixes and cleanups relating to introduction of clustering