Various optimizations and bug fixes. 0.8.0a