fixed bug in waitForP