Add specs, and fix a few bugs that surfaced during testing