Improve performance of wms query