Added logic to handle with the randomic ocurrence of a tail or head