fixed nasty bug for p=2