Made fold tail recursive