This also lays the groundwork for the netjoin batch type, but that isn't implemented yet. I don't like how some of this is implemented but it'll have to do for now... Compile tested, needs more testing.