added cleanhup handler for auto-deregistering