optimize iv calculation