Fix cwd to work with directories specified as variables, too (and a little less hackish)