add test cases and fixed some issues