Wrote the CH function into the script