Modified and fixed bugs by Fang Zhou