fix quoting and simplify upstream reference check