     }
     break;
 }
-while(z > 700 && jointexcess_prevention==0){                              //Tilting the head to the left moves on to the previous joint
+while(z > 600 && z < 700 && jointexcess_prevention==0 && x > 0 && x < 1000 && y > 0 && y < 1000){                              //Tilting the head to the left moves on to the previous joint
    joint--;
    jointexcess_prevention++;
    if(joint < 1){

            infoPk[i] = jelly;
          }

while(z < 300 && jointexcess_prevention==0){                              //Tilting the head to the right moves on to the next joint && h prevents from excessive joint counting.
    joint++;
    jointexcess_prevention++;
    if(joint > 4){

  y = infoPk[15] + (infoPk[14] << 8);
  x = infoPk[17] + (infoPk[16] << 8);
}
  //Serial.print(" X = ") && Serial.print(x);
  Serial.print(" Y = ") && Serial.print(y);
  Serial.print(" Z = ") && Serial.print(z);
  Serial.print(" joint number= ") && Serial.print(joint);
