I think the import should be after the "if" to avoid slowing down the optimization process when it's not applied