minor fixes to error printing and for loop