Refactored optimize doctest