fix #329, fix #396