Handle close signal; minor code cleanup.