Part 1 of code cleanup/optimization.