Fix bugs and warnings.