Comments and a fix for layer freeing.

This has some comments and a small (probably unrelated) uninitialized variable fix resulting from issue #1414.

It seems like the for loop below already initializes that variable. It would probably good to clean up that redundant assignment then, also this could be changed to boolean.