Round of refactoring and improvements