Code lower down looks similar. So this should probably be a function.