some speedups and tweaks