Fix bug when generating scan ranges from prefix