Fixing memory leaks. Using TMath functions instead of TF1