Fixed finding all the layers, and added lots of comments.

The layers are now properly extracted from the locations variable.

I also added long comments about how to proceed to add layer
elements to the DOM.