Fixed "layers" bug

I had previously removed the 'var layers' declaration in favor of just
iterating through the doc.layers directly but didn't update the
reference inside the for loop.