Adding ref counter to layers