Some miscellaneous optimization and cleanup.