fix a regression and undefined selection bug