Decoupled some logic from runtests.sh