Refactor tab tracking, and other misc.