refactored calculator