Add tests

This PR is a work in progress; I'll ping for a merge once I have better coverage.