added error handling to all malloc calls and comments to part1