combine doRunFunction and printFunction