Fixed out of sync and duplication error

Fixed the scenarios where the chunking can cause an out of sync insert with the left over and also duplication creation.