Fixed Stackoverflow error in Mergesort by making the merge method tail recursive.