Refactor cluster stuff into a library