selected attribute now allows array instead of object.
a little code was duplicated, must consolidate it later.