Code cleanup and refactoring to lower CCN.