@thomasmckay, yes, this could be re-factored.