fixes to mallocs and data types