made some fixes to improve logic and readability of monte carlo