refactor string calculator