big refactoring for cluster support