"Total" function gives an incorrect result