Generic dispatcher

Might as well merge this as it seems pretty workable now.