Most of it is legacy code, I'll see if I can collapse into something more generic