fixed permissions bug on OSX and improved large file handling