Fixed max stack size check bug when merging