refactor so settings aren't lost on exit