fixed tail recursion in 4.6 and completed 5.2 with help from the Coursera videos