fix #246 and fix #166