Fix (I think) issues with merge_state and rename dupl functions