modify it to meet my own requirement, and fix some bugs