Your code looks correct to me, and it seems to work as expected in my system. Have you up to date with Personas and kernel patches? It could be that there was a bug that has been fixed recently.
There is one bug I can see in your script, though - your line 'if(temp_def != "")' won't do what you expect. If you don't find the parameter, temp_def will be undefined, which isn't equal to the empty string. Try 'if(!tem_def)' instead.
Steve.