refacto and improvements