Fixes bug in terminate