moved terminate declaration earlier