optimisation at end of recursion