minor mods to r code.