Updated to not set selectedId if it doesn't correspond to an existing element.