Fix some problems relating to working directory being incorrectly set