simplifying first table loops