Try checking for stray semicolons, as one of the for loops might be "empty" if a semicolon is in the wrong place.
Something else you could try is to see the original code and your code side by side to see if you've missed anything.