Various changes and code cleanup.