Added merge-with-class optimization.