fix bugs on memory