properly wrap query