working threadedServer (to be refactored)