Fix error when file is empty, better checks