refactor module context handling