fix bugs, add test and merging