write functions working