revised Jonathan's script for prioritize-proposed-grid.R