finished server logic