fix bug and add test