correction for first and last selection