Remove exception when malloc returns NULL; Prevent divide by zero