Code refactoring and improvements.