Api normalize

This pull completes the functionality discussed in #239, excepting `set` for the text api. I am not sure the best way to implement that. Should I simply remove all existing content, then insert the replacement content?

I also added a bunch of tests for both new and existing functionality. Doing so found several bugs in the existing code, one of which that I could not track down. I disabled its test and opened a separate issue (#242).