Cleanup and add test cases