Refactor calculation