Code Refactoring done as the Problem was a Knapsack Problem