Removed unused functions, changed malloc to checked_malloc