Significant cleanup of code.