Fix some errors with clustering code