Optimizations, bug fixes.