moved temporary arrays to heap