Chained compilation

This seems to work, but needs some review/testing. Will resolve #489.