Almost to a working solution, I think.