Added more test, fix several func