fixed out of order file handling logic