Now cleaning ram correctly and handle graceful stop.