begin writing function