Compound cleanup

I ran out of steam before finishing, but this fixes some bugs in compound.py and adds some test coverage (but not enough to completely finish #203). Have a nice weekend!