quote_if_necessary applied more consistently, updated to use Unix space-escape convention