removed some allocs and converted some to reallocs