fix #663 and fix #664