Added support for custom working directories

A solution to issue #790