Changed how records shared between clusters are saved. Also extracted the executed code to a function.