Formation of well-defined MgO layers