refactored anonymous function and shared calculator