main lib refactored, contexts.js