optimized layer handling