Refactor the context implementation