Refactoring and cleanups.