A nice idiom for iterating over an array like this is to use sizeof(array) / sizeof(array_element), so:
```
for( size_t i = 0; i < sizeof(layer) / sizeof(layer[0]); ++i ) {
```