Moved cofactor functions to local