add loop logic