Fixed silly mistakes in memory index logic. Lots of room for
optimization though