fixed prepare to handle roles and indexes correctly