Clean up and generalization