add new test and fix bugs