Add function for merging piece groups