Refactored calculate method