Fix context manager usage for compatibility with 2.6