The role of surface and gas phase reactions in atomic layer epitaxy