improved resource handling and fixed bug in construct query result generation for large results