fix bug, add regression test