added p>-1 check to all piece checks