Refactor clustering