Don't create the pen before the function is sure to run until the end