Passing a Cache to optimization function

Well glad that fixed it.

Does it now work end to end?

Yes! Just tried it and it worked end to end! Thanks so much.

@wsmoses Just to complete the circle completely, may I ask for a few sentences of explanation as to why the solution you proposed worked?