Some fixes & optimizations.