finished server logic and query distribution