updated for persistent layers and z index updating
fixed precalc bug