all malloc calls moved to use malloc checked