Move this stuff into it's own API