Refactoring and pruning