fixed num_records = -1 bug