Its confusing to have both mode and modes as variable names, especially since the elements of modes are not the same type as the mode variable.  Maybe rename modes to allowedTypes?