fix menu closing in safari, a few other code improvements