merge xuchong's code