some perfomance optimizations
Merge branch 's-hist' into staging2