Updated for memory management.