added check to make sure we have records to insert