fix variable declarations, and only delete stuff if rsync completed successfully