Improved server query code