Improve handling of ${0} when sourced directly, and remove some potential sources of unbound variables