fix bugs and add unit test