improved the loop tremendously