Another missed abstraction that I forgot to mention: all of this error checking should be a callback wrapper.