CHG: extracting code into their own functions