yes, you are right. I used too many temp variables in the function.  I'll spend my weekend to optimize the code, make it more declarative. we can talt about it later.
The extend feature is very useful and necessary. So I advise strongly that it could be merged into the trunk sooner or later. thanks!