added code for nested attributes... messy. Indexes have to be sequential or max no-1 of records will be added... not ideal