PAIP prolog with a little modification