Combined similar operations in import_data function.