Correctly handle character ranges