Use safe_flatten instead of rsync
Move import-only functions out of common