small refactoring and improvements