Port context manager now handles exceptions correctly.