three working loops. almost complete