Added logic to keep menus from spilling off the right of the screen