Total calculation is not working properly