Modified code to work for inverse of matrix instead of mean of vector and altered for greater readability