set up loop for db