p.selected has to return false for the second if block to execute

Verify that p.selected returns false when you think it should