Add integration tests and lots of comments

Lots lots of comments.