add batch function and fix some bugs