Reworks trace function