modified code to produce output for loading by R.