test cases and a few fixes