performance improvements
performance improvements for #1011