Simplified (and hopefully bug-free) mem mgmt.