code cleanup
extract common stuff for test framework