first pass at better memory management