Added debug output for p. Works fine