Added test and fixed bug in total amount