Extracting run function; some reordering