Fix duplicate handling, file parsing logic