Cleanup and generalization