a load of fixes for malloc