Fixed statistics query bugs