restructure menu js code