Regaining sanity

Lots of changes, still not where I'd like but much cleaner.