Improve efficiency of tag-related calls in set()

- Code grouped better to reduce the number of loops
- Add documentation
- Remove a couple of extraneous redis calls