Minor cleanups

Just a few cleanups on really minor issues I noticed along the way. The only thing *slightly* non-obvious is the 'move_tab' thing with the modulo. But it seems correct (and works) and has less code duplication, so there you go.