This patch fixes the index out of bounds error by returning the last item in the list when variable loc is not a valid index.
This patch fixes the index out of bounds error by returning the last item in the list when variable loc is not a valid index.