fix a small bug in test case validation and minor refactoring