Some trimming and refactoring.