added memory and write_back part
removed a commented line
fixed conflicts, fixed the memory call and changed some function order