fix Undefined variable 'p'