fixed issues with heap vs stack memory allocations