Always declare pd and gfx as local variables.
You should only declare them if you are going to use them in the class.

Declare all variables at the top of the init function.
