Updated Function to create inverse Matrix