Move quit hook call to where it's more useful