Refactored to move TriFunction to new "function" package in utils.