added modinv function