added malloc failure checks for oom situations