Context implementation.

Migrated the context related code from the Core to the Context.