Refactoring and clean up.