Fix keep_range and add test cases