Your if statement with the loops did not check for frame(0).