I took a function out and a two loops out
fixed functions and for loops