Converted to "safe" memory mamagement routines in xmalloc.c, logging in log.c, and broke up a couple of larger functions.