added offset check to the memory
fixed conflicts
Merge conflicts with nourhan's mohamed code