Reworking of Filesystem handler 

This is a reworking of the filesystem handler to make some of the code more clear, primarily in an attempt to deal with bugs like that in issue #54.