Fix misc. bugs related to selected being null