fixed references of loops
fixed references of conditions