Improved context factory.