Refactoring the discount calculation