Thanks, but this code also looks ok, so if your script crashes it's still something else.
If you can't immediately see the reason of a crash in your script, start with a minimum version - just the lines above that you posted, including the info command - and then add the rest step by step. At one point it will crash. Not always, but often the crash reason are the last lines that you added.