Some optimizations & fixes.