wired up a shutdown handler; bug fixes