Modified to store records to Failed Records table