implemented the merge algorithm
treat state variables of type nat as ints