Fixed bad reference to doc.layers.length

Reference should have been to doc.layers