Tracked down a nasty segfault
Now abstracting more common code.