fixed the tri function