Need to fix frees and remove excess mallocs