Source code cleanup, test cases added.