Refactor and style cleanup.