Update test cases and fix bugs