writing function