Before mem opt

Merge  branch before_mem_opt