Added testcases. (and found some bugs.)