Fixes #1041. Bug in P func