Factoring out some code.