Refac common code into generic