Some more auto-detection support.

Lots of generalized improvements.