Rewrote the defineMemory function
Fixed a few issues with defineMemory