Move memory read functions to memory.c