Refactoring and clean up. No behaviour change.