add callback and fix a bug