refactor some calculator code