refactored runtest code