Deal with ranges input to save queries