Fix some compiler warnings and more performance improvements.