Fix illegal access to undefined/dead objects