split cluster handling code out into separate module