P01 with API and tailrec