Improve addMenuItem function