fix p = -1 issue