fix #654, fix #312