Many bug fixes

Discovered when I tried to use DYE on a project of my own. You might like to review these and merge them if necessary.