Check if this is your problem.
Eliminate "restart layout" because you are resetting the layout to the initial values, then you can never set the new values.
Thanks, mink for sharing the solution. though I can't remove the restart layout as it plays a cruicial part in my code. I spent some more time and got the issue fixed with keeping restart functionality intact.