Made file loading much more robust