Move write edges into a funcion