Undefined variable error and better filesystem error handling

Resolves #178