Refactored so that file metadata is only sent once