minor cleanups and add more test cases.