Fixes #421

I re-implemented the logic from 0.5.0, and lo, it works.