Extract unit of work runner

for #552 

@johnsimons @andreasohlund @indualagarsamy code review please