Added total.
Fixed bugs.
Fixed bug in total