Rewrote and corrected how tag ranges are handled

After looking into the code and discussing with Richard and Oz.