weird loop referencing, can't just go 0 to P-1