Fix a lot of bugs and add many functions......