Split code into smaller functions to make code more coherent
Changed test function to take in new test targets and cases.