Some small refactorings and improvements.