wrote function