refactored recursive functions; added tail example