Refactoring class Knapsack