Started restructuring, errors,  nested loops