More common code into functions.