More test cases + bug fixes