got rid of some duplicate code with a function that focuses on the first or last item in a menu