work-in-progress refactoring of the layer calculation