Various cleanup optimize

The first commit is mainly to increase consistency in how the stories and tags are categorized. This might be useful when adding support for header-specific special passages and tags later. It might also improve performance by using set operations (in particular, isdisjoint) instead of iterating through lists. And I believe it fixes 1 bug with passages included from .tws files, see commit comment for details.

The second commit contains optimizations that should reduce build time on large stories.

The third commit is a minor cleanup to improve readability of the code.