Refactored calls to malloc() into memory.c