Add check to selection end index