optimization in extractranges()