small fixes and speedups