Restructured calibrate.R to pass inspection for CRAN. Other minor changes.