refactor caculate_total method