I don't qualify as a master, but I'll comment anyway.
Where/how are you calling the nested functions?
The construction looks fine at first glance.
Keep in mind that 'form follows functionality'
... There is no "ideal" structure as such because the code design depends on what problem you are trying to solve.
Personally I prefer to keep my code modular; that is, use lots of smaller functions rather than one big one.
I find that this makes testing easier and helps to simplify changes to the code.
Something that a lot of people forget is to document the function.
NOT write comments every second line but rather explain the purpose of the function, the parameter types and the expected input and output.
Here's an example of a function signature that explains at a glance the purpose of the function. This becomes important when you re-visit the code later.
http://www.theswamp.org/index.php?topic=49771.msg549351#msg549351Regards,