added auto-exit to end as well