Improving the implementation using a tail reference