Bug fixes. Script now works!
Changed -r to -f to better reflect what's actually done.