Move common code to util module