Extract common code from functions.