Update test cases; fix bugs