Improve function for computing minor