added code to exit function if one of the test results is invalid