Added layersToZ3 and layersToZ4 functions to simplify code.