arrange functions of making menuitems

* no feature changes
* rename/remove local variables
* modulize some functions
minor fix

* format array items
* rename handler name
* update comments