avoiding negative p while generation