lots of enhancements and cleanup