Updated code for Inv