changed gridselect workspace common code to a function