Made changes in 2nd function to calculate inverse