add code to halt cleanly