Small refactorings and improvements