This could be factored out in a function.