more refactoring: introduced a per-function context to make extending and api-fying mscm easier (but not yet done)