added tailrec annotations