added cache writing (memory writing not yet done)
merged changes