add tests. improve total calculations