In the code below you appear to be using activity.data.modes, not activity.modes, so I think this code will not work.