Refactor clustering/api