fix #687 and add test