Added code for native terminate, better for xia2.