Cleanup and refactoring prompted by instructions.