refactor calculator to support train