Factored out code.