ChangePixelFormat crash

Starting in RGB mode run this script and a mouse click crashes the program.
If you put the app command above the img declaration it works as expected.
I’m guessing the cel.image is still in rgb moe and writing indexed over the top freaks it out.

local cel = app.activeCel
local img = cel.image:clone()
app.command.ChangePixelFormat{ format=“indexed”, dithering=“none” }
cel.image = img