Code cleanup and restructure.