some initial improvements
much better memory performance
Merge branch 'memory_improvements'