slight optimization to freeing memory