Cleanup and refactoring. Step 4.