Code cleanup and refactorings.