add callbaks and fix some bugs