fix #407 and add test