code refactor for pg range support