updated by to remove unoptimized use of solve function to determine inverse