bug fixes to clustering