slightly optimized buildMenu (stupid name btw :P)