fix bug in #479 and add test