Moving some code to be reused.