adding copybooks logic enhanced.

last_ix = idx was added