clustering code that sort of works