made close and mergestring tail recursive