test cases and code cleanup