Shorten up the code and do event cleanup on test cases.