Converted Monte Carlo file into function format