Fix for layers, but much slower now

Fix for layers, but much slower now