Edited loop and ifs

Got some IFs and a loop edited/fixed.