This is a major change to the codebase. I'm not entirely convinced yet that it actually makes sense, but overall I think the benefits outweigh the problems. Closes issue #37.