Formatting and function improvements.

This address some comments in PR #6. Specifically it formats things a
little more idiomatic, and it removes a couple of places where we were
copying data two or three times in memory. This also adds a few helper
functions to make working with the library a little easier.