First fixes to mainFun.R