Ensure cwd is determined correctly, panic crash otherwise.

This may help with #8.