initialized default mem_max to -1
fixed lvalue bug