I implemented it this way because I thought it would be a more elegant solution. Shouldn't tail recursive calls be optimized?