Add final modifier and @tailrec

Signed-off-by: Gary Pamparà <gpampara@gmail.com>