working version, memory size stable