Some enhancements and cleanup from the previous version..