Fixed up to work properly with selection and refreshing.