It is really hard to follow and seems like the cleaning is not finished there.
There are non-existing function, finalize_solution is forgotten and a lot of non-relevant debug-style code.
I made this issue to track the progress of this example.
let's fix this.
Please ensure script is runnable from the start to the end without model saves created in different sessions.