more minor speedups and refactors