cleaned up loop