Surface and subsurface reaction mechanisms in atomic layer deposition of metals and metal oxides