Added countInv function (not working now)