Tring to fix bugs in memory.c