write functions implementations