refactoring getP bug fix