Merge pull request #710 from stianst/clustering

Fixes to clustering