major refactor: global data, faster switching