change logic to nested arrays]