almost correct tail recurisive chapter 4 function