memory leak changes and mergesort added