UNTESTED COMMIT. Cleaned up lots of code but no change of functionality. Found several repeated examples of poor coding.