Added total value consideration in comments
Closed if block
Bug fix with argument error
Added test cases