fixed implementation in #30

Here's a more robust implementation of PR #30 which also handles relative file paths correctly