Numerous enhancements and cleanup.