NB and P fixed and tested for bugs