changed code for "r" flag