Improve error handling, make working dir easier to change