finish test and fix some code bugs