Fixed a couple of bugs when dealing with files