Rafactoring and improvements