bugfix and add test case