Performance enhancements and cleaning up some code.