gh-6 seems to have similar code - could this be factored out (maybe after merging both)/