Bugfix in layer calculation.