Incorporate proper handling of working directory.

Allow the code to be called from any directory by switching to the working directory upfront.