reorganized code for easier rsync