fix bugs
fix a lot of bugs, can run now. results are not tested