Fix bugs caused by memory garbage.