Updated so that the auto-allocation works correctly and also handles the case of file format being incorrect.