Integrate Ming's code