add log and fix some bugs