Modified matrix inverse function to check for zero determinant and added unit test