Now that I see this clearly I think it's a candidate to be extracted to a method, or better yet pushed down into the `layer` object, both with a meaningful name.