Compound cleanup

I ran out of steam before finishing, but this fixes some bugs in compound.py and adds some test coverage. Have a nice weekend!