added check for last item in forloop