two testcases
reorganized the code structure, reduced duplication and code readability