NF Added total_variation function