Source for the ginv function added to make calculations smoother