I have a good written function; I guess, but when I use this function on a client that has many transactions it takes like 20 seconds, increasing everytime I add new transac