Refactoring and improvements.