added recursive and tailrec annotated function