added a function to set the working directory
ignores CWD if dir is already set