separated functions
added threads