refactor; make overall calculation work