removed mallocs, kept arrays, checked castes. Compiles and flashes, not yet working.