Removed reduntant recursive functions and added tailrec annotation where
appropriate