Adding comments

Now Memory.cpp and Memory.h are fully commented. Some minor changes due
to improve performance.