Move shutdown terminal reset to finalize()

Fixes classloader leak.