You need to have the variables in the class and not local to the function