added a tailrec annotation