Cleaned up terminating code