a bunch of efficiency hacks and speedups