Added clear total. Refactored Devan's code.