fix bugs in $ORIGIN handling